<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\date\DatePicker;
use app\modules\Basic\models\CityCode;
use kartik\select2\Select2;
use app\modules\Manage\models\User;

//获取城市
$city = CityCode::find()->all();
$citys = [];
foreach($city as $ct){
    $citys[$ct->code] = $ct->code.'——'.$ct->en_name.'——'.$ct->zh_name;
} 

//获取所有员工
$data_s = User::find()->where(['status'=>10])->andWhere(['not in','id',[1,2,3]])->all();
$users = [];
if($data_s){
    foreach($data_s as $ds){
        $users[$ds->id] = $ds->name;
    } 
}


if(!is_array($model->city)){
    $model->city = json_decode($model->city);
}
if(!is_array($model->member_id)){
    $model->member_id = json_decode($model->member_id);
}

?>

<div class="product-serve-form">

     <?php $form = ActiveForm::begin([
             'options' => ['enctype' => 'multipart/form-data',],
             'layout' => 'horizontal',
             'fieldConfig' => [
                'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                'horizontalCssClasses' => [
                    'label' => 'col-sm-2',
                    'wrapper' => 'col-sm-7',
                    'error' => '',
                ],
             ],
        ]); ?>

    <?= Html::activeHiddenInput($model, "product_id");?>

     <?php  echo '<div class="form-group" style="margin-bottom:30px;"><label class="control-label col-sm-2">日期</label><div class="col-sm-7">';
    echo DatePicker::widget([
        'model' => $model,
        'attribute' => 'begin_date',
        'attribute2' => 'end_date',
        'options' => ['placeholder' => '开始日期'],
        'options2' => ['placeholder' => '结束日期'],
        'type' => DatePicker::TYPE_RANGE,
        'form' => $form,
        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'autoclose' => true,
        ]
    ]);

    echo '</div></div>';
    ?>
     <?= $form->field($model, 'city')->widget(Select2::classname(), [
                'data' => $citys,
                'language' => 'zh-cn',
                'options' => ['multiple'=>true,'placeholder' => '选择城市'],
                'pluginOptions' => [
                    'allowClear' => true,
                ],
            ]); ?>


    <?= $form->field($model, 'member_id')->widget(Select2::classname(), [  
                              'language' => 'zh-cn',
                              'options' => ['multiple'=>true,'placeholder' => '选择服务经理'],
                              'data' => $users,
                              'showToggleAll' => false,
                              'pluginOptions' => [
                                  'allowClear' => true,
                              ],
                          ])?>

    <div class="form-group text-center">
        <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
